package top.ed333.mcplugins.configurableevents.requirement;

import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.jetbrains.annotations.NotNull;

public class PlayerHasItemWithNameReqGroup extends TargetedByPlayerEventReqGroup {
    public PlayerHasItemWithNameReqGroup(String groupName, @NotNull String ext) {
        super(groupName, ext);
    }

    @Override
    public String name() {
        return "PlayerHasItemWithName";
    }

    @Override
    public boolean checkReq(@NotNull PlayerEvent event) {
        Player player = event.getPlayer();
        Inventory playerInv = player.getInventory();
        boolean result = false;
        for (ItemStack item : playerInv.getContents()) {
            ItemMeta meta = item.getItemMeta();
            if (meta.getDisplayName().equals(getExt().toString())) {
                result = true;
                break;
            }
        }
        return result;
    }
}
